﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FlickrNet;
using Project3.Models;
using Project3.Models.FlickrNet;

namespace Project3.Controllers
{
    namespace FlickrNet
    {
        public class PhotoController : Controller
        {
            MeetingsRepository meetingsRepository = new MeetingsRepository();
            FlickrPhotos flickrPhotos = new FlickrPhotos();

            //
            // GET: /Photo/

            public ActionResult Index()
            {
                return View(meetingsRepository.FindUpcomingMeetings().ToList());
            }


            //
            // GET: /Photo/MeetingPhoto/2?page=2

            public ActionResult MeetingPhoto(int id,int page)
            {
                // Handle pages out of range
                if (page < 1)
                {
                    page = 1;
                }
                if (page > flickrPhotos.numPagesMeeting(id))
                {
                    page = flickrPhotos.numPagesMeeting(id);
                }

                PhotoCollectionAndId collect = new PhotoCollectionAndId();
                collect.collection = flickrPhotos.getPhotosFromMeeting(id,page);
                collect.id = id;
                collect.meeting = meetingsRepository.GetMeeting(id);
                return View(collect);
            }

            //
            // GET: /Photo/IndividualPhoto/2

            public ActionResult IndividualPhoto(int id, Int64 photoID)
            {

                PhotoCollectionAndId collect = new PhotoCollectionAndId();
                collect.collection = flickrPhotos.getPhoto(photoID);
                collect.id = id;
                return View(collect);
            }
        }
    }
}
